package com.oros.db;

import java.io.Serializable;


public class AEFilter implements Serializable {

	private static final long serialVersionUID = -6092813255736161791L;
	public enum FilterOperator{EQUAL,GREATER_THAN,GREATER_THAN_OR_EQUAL,IN,LESS_THAN,LESS_THAN_OR_EQUAL,NOT_EQUAL};
		String columnName;
	    FilterOperator filterOperator;
	    Object value;
	    Class<?> type;
	    private int hashcode,columnNo;
	    private boolean parentColumnUsed=false;
    public AEFilter(String columnName,FilterOperator filterOperator,Object value,Class<?> type,int columnNo)
    {
    	this.columnName = columnName;
    	this.filterOperator = filterOperator;
    	this.value = value;
    	this.type = type;
    	this.columnNo = columnNo;
		final int prime = 31;
		hashcode= ((columnName == null) ? 0 : columnName.hashCode());
		hashcode = prime * hashcode
				+ ((filterOperator == null) ? 0 : filterOperator.hashCode());
		hashcode = prime * hashcode + ((value == null) ? 0 : value.hashCode());
	}
    public boolean isParentColumnUsed() { return parentColumnUsed;}
    public void setParentColumnUsed() { parentColumnUsed=true;}
    public String getColumnName() { return columnName; }
    public int getColumnNo() { return columnNo;}
    public Class<?> getType() { return type; }
    public FilterOperator getFilterOperator()
    { return filterOperator; }
    public Object getValue() { return value; }
    public void setValue(Object val)
    {
    	if (!value.equals(val))
    	{
    		hashcode = hashcode - value.hashCode() + val.hashCode();
    		value = val;
    	}
    }
	@Override
	public int hashCode() {
		return hashcode;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AEFilter other = (AEFilter) obj;
		if (columnName == null) {
			if (other.columnName != null)
				return false;
		} else if (!columnName.equals(other.columnName))
			return false;
		if (filterOperator != other.filterOperator)
			return false;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}
    
}
